package com.example.springbootbabyu.mapper;

import com.example.springbootbabyu.entity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface CategoryMapper {
    // 查询一级分类信息
    @Select("SELECT id, name, picture FROM category WHERE id = #{id}")
    CategoryResult selectParentCategory(@Param("id") String id);

    // 查询二级分类列表
    @Select("SELECT id, name, picture, parent_id, parent_name FROM category WHERE parent_id = #{id}")
    List<CategoryDTO> selectSubCategories(@Param("id") String id);

    // 查询分类下的商品
    @Select("SELECT id, name, `desc`, price, picture, discount, order_num FROM goods WHERE category_id = #{categoryId}")
    List<GoodsDTO> selectGoodsByCategory(@Param("categoryId") String categoryId);

    // 查询2级分类的筛选条件
    @Select("SELECT id, name, picture, parent_name FROM category WHERE parent_id = #{id}")
    CategorySubFilter selectCategoryFilter(@Param("id") String id);

    @Select("SELECT * FROM goods WHERE category_id = #{id} ORDER BY order_num LIMIT #{pageNum}, #{pageSize}")
    List<CategoryGoods> selectSubCategoryGoods(String id, Integer pageNum, Integer pageSize);
}
